package org.codeart.api_driver.controller;

import lombok.extern.slf4j.Slf4j;
import org.codeart.api_driver.service.VerificationService;
import org.codeart.common.dto.VerifyCodeDTO;
import org.codeart.common.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
public class CodeController {
    
    @Autowired
    private VerificationService verificationService;

    @GetMapping("/verification-code")
    public R<Void> verifyCode(@RequestParam("driverPhone") String phone) {
        log.info("司机的号码: {}", phone);
        boolean b = verificationService.checkAndSendVerificationCode(phone);
        if (b) {
            return R.ok();
        }
        return R.fail();
    }
    
    @PostMapping("/verification-code-check")
    public R<?> checkCode(@RequestBody VerifyCodeDTO verifyCodeDTO) {
        String driverPhone = verifyCodeDTO.getDriverPhone();
        String verificationCode = verifyCodeDTO.getVerificationCode();
        log.info("手机号: {}, 验证码: {}", driverPhone, verificationCode);
        return verificationService.checkCode(driverPhone, verificationCode);
    }
}
